function [model]=variational_EM_fdebug(data, MAXCOUNT, MAXESTEPITER, MAXMSTEPITER, MaxFun)


%global model;
warning off;
model=[];

LOWLIMIT=0.01;
convergence=1000000;
model=init_params(data);
countVEM=1;
model.k=data.k;
model.k_hat=data.k_hat;
maxvalue = -10000000000;


%save model;
while (convergence> LOWLIMIT && countVEM<MAXCOUNT)
    
    [value1] = cal_likelihood(model, data);
    
    
    if (compareval(value1, maxvalue))
        maxvalue = value1;
        disp('correct');
    else
        disp('Incorrect');
        keyboard;
    end
    
    
    model    = E_step_fdebug(model,data, MAXESTEPITER, MaxFun, maxvalue, countVEM);
    [value2] = cal_likelihood(model, data);
    
    
    if (compareval(value2, maxvalue))
        maxvalue = value2;
        disp('correct');
    else
        disp('Incorrect');
        keyboard;
    end
    
    
    model    = M_step_fdebug(model,data, MAXMSTEPITER, MaxFun, maxvalue, countVEM);
    [value3] = cal_likelihood(model, data);
    
    if (compareval(value3, maxvalue))
        maxvalue = value3;
        disp('correct');
    else
        disp('Incorrect');
        keyboard;
    end
    
    
    convergence=100*abs((value3-value1)/value1);
    value1=value3;
    value(countVEM)=value1;
    %value3(count)=value22c;
    disp('count from V-EM');
    countVEM = countVEM+1
    
end

figure(2), plot([1:countVEM-1],value,'b.-');

accval = cal_accuracy(model, data)

%word_prob(model,vocab,10);
%topic_prob(model,unique_str_nbr);
end
